package com.renjibo.sharkerwave.ui.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.renjibo.sharkerwave.R;

public class LoginActivity extends BaseActivity implements View.OnClickListener {

    private EditText login__editText_password;
    private ImageView login_image_set__password;
    private boolean showPassword;
    private final int type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Toolbar toolbar = (Toolbar) findViewById(R.id.login_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        initView();
    }

    private void initView() {
        findViewById(R.id.login_imageView_register).setOnClickListener(this);
        findViewById(R.id.login_imageView_left).setOnClickListener(this);
        findViewById(R.id.login_image_set__password).setOnClickListener(this);
        login__editText_password = (EditText) findViewById(R.id.login__editText_password);
        login_image_set__password = (ImageView) findViewById(R.id.login_image_set__password);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //注册
            case R.id.login_imageView_register:
                Intent intent = new Intent(this, RegisterActivity.class);
                startActivity(intent);
                break;
            //关闭页面
            case R.id.login_imageView_left:
                finish();
                break;
            //显示隐藏密码
            case R.id.login_image_set__password:
                if (showPassword) {
                    showPassword = false;
                    login_image_set__password.setImageResource(R.drawable.login_no_password);
                    login__editText_password.setInputType(type);
                    login__editText_password.setSelection(login__editText_password.getText().length());
                } else {
                    showPassword = true;
                    login_image_set__password.setImageResource(R.drawable.login_show_password);
                    login__editText_password.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
                    login__editText_password.setSelection(login__editText_password.getText().length());
                }
                break;
        }
    }
}
